package com.woniu.platform.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.platform.entity.PlatformRecommendationRecord;
import com.woniu.platform.mapper.PlatformRecommendationRecordMapper;
import com.woniu.platform.service.PlatformRecommendationRecordService;
import com.woniu.util.utils.HttpResult;
import com.woniu.util.utils.RequestResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Service
@Slf4j
public class PlatformRecommendationRecordServiceImpl implements PlatformRecommendationRecordService {

    @Autowired(required = false)
    private PlatformRecommendationRecordMapper recommendationRecordMapper;
    @Override
    public HttpResult insertRecommendation(PlatformRecommendationRecord recommendationRecord) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        recommendationRecord.setRecommendationTime(dateFormat.format(new Date()));
        recommendationRecord.setAuditResult(0);
        int re = recommendationRecordMapper.insert(recommendationRecord);

        if(re>0){
            return new HttpResult().ok();
        }else{
            return new HttpResult().fail();
        }
    }

    @Override
    public HttpResult selectRecommendationByCoreId(RequestResult<PlatformRecommendationRecord> requestResult) {
        PageHelper.startPage(requestResult.getPageNum(),requestResult.getPageSize());
        List<PlatformRecommendationRecord> list = recommendationRecordMapper.queryRecordsByCoreID(
                                                                                    requestResult.getData().getCoreName(),
                                                                                    requestResult.getData().getFinanceName(),
                                                                                    requestResult.getData().getAuditResult(),
                                                                                    requestResult.getData().getCoreId());
        PageInfo pageInfo = new PageInfo(list);
        log.info("参数为:{}",pageInfo);
        return new HttpResult().ok(pageInfo);
    }

    @Override
    public HttpResult updateRecord(PlatformRecommendationRecord recommendationRecord) {
        int re = recommendationRecordMapper.updateById(recommendationRecord);
        if(re>0){
            return new HttpResult().ok();
        }else{
            return new HttpResult().fail();
        }
    }
}
